import request from "../utils/request";
// import { useMessage } from "naive-ui";
// const messageBox = useMessage();
export default {
  // 是否登陆
  isLogin() {
    try {
      let token = window.localStorage.getItem("token");
      if (token) {

        // 将 token 通过 POST 请求发送到 /api/admin/islogin

        const res = request({
          url: "/api/admin/islogin",
          method: "post",
          data: { token: token }
        }).then((response) => {
          console.log(response);
          if (response?.code > 0) {
            console.log('已登录', response?.data);
            // messageBox.success("已登录");
            return true;
          } else {
            console.log('未登录', response?.msg);
            // messageBox.error("未登录");
            return false;
          }
        }).catch((error) => {
          console.error("Request error:", error);
          return false;
        });

      } else {
        return false;
      }

      return !!token;
    } catch (error) {
      console.error("Error accessing localStorage:");
      return false;
    }
  }
}